<?php
namespace cms\modules\v1\controllers;

use cms\modules\v1\models\access\ModuleActions;
use cms\modules\v1\models\coin\CoinRechargeOrder;
use cms\modules\v1\models\coin\CoinRechargeSetting;
use cms\modules\v1\models\userLevel\UserLevel;
use common\models\Functions;
use common\models\Status;
use Yii;
use yii\filters\auth\HttpHeaderAuth;
use yii\helpers\ArrayHelper;
use cms\modules\v1\models\user\UserReal;

class CoinController extends DefaultController
{
    public $modelClass = 'cms\modules\v1\models\coin\CoinRechargeSetting';
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' =>  HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [                     //需要过滤掉不用token参数的方法

                ]
            ]
        ]);
    }

    /* ====================== 金币充值规格 ========================= */
    //级别列表
    public function actionList($page = 1, $size = 20) {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return (new CoinRechargeSetting())->getListData($page, $size);
        }
    }

    //添加修改
    public function actionAddEdit($id = 0) {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        $model = new CoinRechargeSetting();
        if (Yii::$app->request->isGet) {
            return $model->getInfo($id);
        }

        if (Yii::$app->request->isPost) {
            $model->setScenario('addEdit');
            if ($model->load(Yii::$app->request->post(), '')) {
                return $model->addEdit();
            }
        }
    }

    /**
     * 切换状态
     * @return array
     */
    public function actionSetField() {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isPost) {
            return (new CoinRechargeSetting())->setField();
        }
    }

    //map
    public function actionMap () {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return (new CoinRechargeSetting())->getSelectMap();
        }
    }

    /* ====================== 金币订单 ========================= */
    //列表
    public function actionOrderList($page = 1, $size = 20){
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return (new CoinRechargeOrder())->getListData($page, $size);
        }
    }

    /**
     * 切换状态
     * @return array
     */
    public function actionDelOrder() {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (Yii::$app->request->isGet) {
            return (new CoinRechargeOrder())->saveDelOrder();
        }
    }



}
